﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MotionCS.Helper
{
    /// <summary>
    /// 单例模式的基类
    /// </summary>
    public abstract class SingleObjectBase<T>
        where T : class
    {
        /// <summary>
        /// 单例锁对象
        /// </summary>
        private static object objLock = new object();

        /// <summary>
        /// 单例的实例对象
        /// </summary>
        private static T instance;


        /// <summary>
        /// 单例的实例对象
        /// </summary>
        public static T Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (objLock)
                    {
                        if (instance == null)
                        {
                            instance = Activator.CreateInstance(typeof(T), true) as T;
                        }
                    }
                }

                return instance;
            }
        }

        public SingleObjectBase()
        {

        }
    }
}
